package com.netdisk.mapper;
import com.netdisk.dto.request.file.DeleteDTO;
import com.netdisk.entity.File;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface FileMapper {
    void insert(File file);
    void clear(Integer id);
    void delete(DeleteDTO deleteDTO);
    @Select("select count(*) from files where user_id = #{userId};")
    Integer getFileCountById(Integer userId);

    @Select("select * from files where user_id = #{userId} limit 0,10;")
    List<File> getFileListById(Integer userId);

    @Select("select * from files where user_id = #{userId} and id = #{id};")
    File getFileById(@Param("userId") Integer userId, @Param("id") Integer Id);

    /*添加回收站*/
    @Update("update files set deleted_at = now() where id = #{id} ;")
    void deleteFile(Integer id);

    /*从回收站恢复文件*/
    @Update("update files set deleted_at = null where id = #{id};")
    void restoreFile(Integer id);

    /*将文件添加到收藏*/
    @Update("update files set is_favorite = 1 where id = #{id};" )
    void addFavorite(File file);

    /*将文件移除收藏*/
    @Update("update files set is_favorite = 0 where id = #{id};")
    void cancelFavorite(File file);

    /*修改文件名*/
    @Update("update files set name = #{newName} where id = #{id}")
    void renameFile(@Param("id") Integer id, @Param("newName") String newName);
}
